import 'package:PollOnLine/ui/home/task_list/task_list_view_ipad.dart';
import 'package:PollOnLine/values/MyColors.dart';
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../r.dart';
import 'home_logic.dart';
import 'task_list/task_list_view.dart';
import 'triangle_decoration.dart';

class HomePageIpad extends StatefulWidget {
  final String title;

  const HomePageIpad({Key? key, required this.title}) : super(key: key);

  @override
  State<HomePageIpad> createState() => _HomePageIpadState();
}

class _HomePageIpadState extends State<HomePageIpad> {
  final logic = Get.put(HomeLogic());
  final state = Get.find<HomeLogic>().state;

  @override
  Widget build(BuildContext context) {
    return OrientationBuilder(builder: (context, orientation) {
      return GetBuilder<HomeLogic>(builder: (logic) {
        return Scaffold(
          backgroundColor: MyColors.FFEDF1F5,
          body: Stack(
            children: [
              Image.asset(orientation == Orientation.portrait ? R.assetsImgBgHome1Ipad : R.assetsImgBgHome1IpadL,
                  fit: BoxFit.fill, width: Get.width, height: 186.r),
              Column(
                children: [
                  SafeArea(
                    child: Container(
                      margin: EdgeInsets.only(left: 13.r, right: 12.r, top: 11.r),
                      child: Row(
                        children: [
                          Image.asset(R.assetsImgIconHome1, fit: BoxFit.fill, height: 15.5.r, width: 63.5.r),
                          Expanded(
                            child: Padding(
                              padding: EdgeInsets.only(left: 14.5.r),
                              child: ClipRRect(
                                borderRadius: BorderRadius.all(Radius.circular(10.r)),
                                child: SizedBox(
                                  height: 20.r,
                                  child: Center(
                                    child: BrnSearchText(
                                      innerPadding: const EdgeInsets.all(0),
                                      maxHeight: 20.r,
                                      hintText: "请输入任务关键字",
                                      hintStyle: TextStyle(color: MyColors.FF888888, fontSize: 9.r),
                                      textStyle: TextStyle(color: MyColors.FF888888, fontSize: 9.r),
                                      prefixIcon: Container(
                                          padding: EdgeInsets.only(left: 13.5.r, top: 5.r, bottom: 5.r),
                                          child: Image.asset(R.assetsImgIconHome2, width: 13.r)),
                                      innerColor: Colors.white,
                                      borderRadius: BorderRadius.all(Radius.circular(10.r)),
                                      normalBorder: Border.all(color: Colors.white, width: 1, style: BorderStyle.solid),
                                      activeBorder: Border.all(color: Colors.white, width: 1, style: BorderStyle.solid),
                                      autoFocus: false,
                                      onTextClear: () {
                                        return false;
                                      },
                                      action: Container(),
                                      onActionTap: () {},
                                      onTextCommit: (text) {},
                                      onTextChange: (text) {},
                                    ),
                                  ),
                                ),
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                  Container(
                    width: Get.width,
                    margin: EdgeInsets.only(left: 9.r, right: 9.r, top: 15.r),
                    child: TabBar(
                      controller: logic.tabController,
                      padding: EdgeInsets.all(0.r),
                      // 是否自动调整indicatorColor
                      automaticIndicatorColorAdjustment: true,
                      // 指示器
                      indicator: TriangleIndicator(triHeight: 10.r),
                      indicatorColor: Colors.white,
                      indicatorWeight: 4,
                      // indicatorPadding: EdgeInsets.only(left: 30.r, right: 30.r),
                      // indicatorSize: TabBarIndicatorSize.label,
                      // 分割线
                      dividerHeight: 0,
                      dividerColor: Colors.transparent,
                      // 选中文字内边距
                      labelPadding: EdgeInsets.only(left: 3.r, right: 3.r, top: 0.r, bottom: 0.r),
                      // isScrollable: true,
                      // physics: const BouncingScrollPhysics(),
                      // tabAlignment: TabAlignment.start,
                      tabs: [
                        for (var i = 0; i < state.tabs.length; i++)
                          Tab(
                            height: orientation == Orientation.portrait ? 42.r : 32.r,
                            child: Container(
                              padding: EdgeInsets.only(left: 10.r, right: 10.r),
                              decoration: BoxDecoration(
                                color: logic.isChoose(i) ? Colors.white : Colors.white.withOpacity(0.25),
                                borderRadius: BorderRadius.circular(5.r),
                              ),
                              child: Center(
                                child: orientation == Orientation.portrait
                                    ? Column(
                                        mainAxisAlignment: MainAxisAlignment.center,
                                        children: [
                                          Text(state.tabs[i].num,
                                              style: TextStyle(color: logic.isChoose(i) ? MyColors.FF1C71E5 : Colors.white, fontSize: 12.r)),
                                          Text(state.tabs[i].title,
                                              style: TextStyle(color: logic.isChoose(i) ? MyColors.FF1C71E5 : Colors.white, fontSize: 10.r)),
                                        ],
                                      )
                                    : Row(
                                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                        children: [
                                          Text(state.tabs[i].title,
                                              style: TextStyle(color: logic.isChoose(i) ? MyColors.FF1C71E5 : Colors.white, fontSize: 10.r)),
                                          Text(state.tabs[i].num,
                                              style: TextStyle(color: logic.isChoose(i) ? MyColors.FF1C71E5 : Colors.white, fontSize: 12.r)),
                                        ],
                                      ),
                              ),
                            ),
                          ),
                      ],
                    ),
                  ),
                  Expanded(
                    child: Container(
                      margin: EdgeInsets.only(left: 12.r, right: 12.r, top: 10.r, bottom: 8.r),
                      child: TabBarView(
                        controller: logic.tabController,
                        children: [for (final tab in state.tabs) TaskListPageIpad(title: '任务列表', tab: tab)],
                      ),
                      // child: PageView(
                      //   controller: logic.pageController,
                      //   children: [for (final tab in state.tabs) TaskListPage(title: '任务列表', tab: tab)],
                      //   onPageChanged: (int index) {
                      //     logic.tabController.animateTo(index);
                      //   },
                      // ),
                    ),
                  ),
                ],
              ),
            ],
          ),
        );
      });
    });
  }

  @override
  void dispose() {
    Get.delete<HomeLogic>();
    super.dispose();
  }
}
